package Text47;

import java.util.*;

public class Main {
    static int N = 5010;
    static PII[] p = new PII[N];
    static int[] f = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            p[i] = new PII(x, y);
        }
        Arrays.sort(p, 1, n + 1);
        for (int i = 1; i <= n; i++) {
            f[i] = 1;
            for (int j = 1; j <= n; j++) {
                if (p[i].y > p[j].y) {
                    f[i] = Math.max(f[i], f[j] + 1);
                }
            }
        }
        int res = 0;
        for (int i = 1; i <= n; i++) {
            res = Math.max(res, f[i]);
        }
        System.out.println(res);
    }
}

class PII implements Comparable<PII> {
    int x, y;

    public PII(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public int compareTo(PII o) {
        return Integer.compare(this.x, o.x);
    }
}